<template>
 <div>
     <h2>添加书籍</h2>
     书名：<input type="text" v-model="book_name">
     封面：<input type="file" id="img">
     简介：<input type="text" v-model="desc">
     分类：<select v-model="cate">
         <option v-for='i in cate_list' :value="i.id" :key="i.id">{{i.book_name}}</option>
     </select>
     价格：<input type="number" v-model="price">
     <button @click="sub">添加</button>
 </div>
</template>

<script>
 export default {
   data () {
     return {
         book_name:'',
         desc:'',
         cate:'0',
         cate_list:[],
         price:0
     }
   },
   mounted(){
       this.axios({
           url:'http://127.0.0.1:8000/app01/get_cate/',
           method:'get',
       }).then(res=>{
           this.cate_list=res.data.data;
       })

   },
   methods: {
       sub:function(){
           let img=document.getElementById("img").files[0];
           let formdata=new FormData();
           formdata.append("nabook_nameme",this.book_name);
           formdata.append("cate",this.cate);
           formdata.append("desc",this.desc);
           formdata.append('price',this.price);
           formdata.append("img",img);
           this.axios({
               url:'http://127.0.0.1:8000/app01/book/',
               method:'post',
               data:formdata
           }).then(res=>{
               alert(res.data.msg);
           })
       }
   }
 }
</script>

<style>

 
</style>
